import request from "@/utils/request";

/**@reqCategoryItemType 商品属性的返回值每一项的类型*/
export interface reqCategoryItemType {
  id: number;
  name: string;
  category1Id?: number;
  category2Id?: number;
}

/**@reqCategoryListType 商品属性的返回值*/
export type reqCategoryListType = reqCategoryItemType[];

/**@requestCategoryList1  请求一级列表 */
export const requestCategoryList1 = () => {
  return request.get<any, reqCategoryListType>(`/admin/product/getCategory1`);
};

/**@requestCategoryList2  请求二级列表 */
export const requestCategoryList2 = (category1Id: number) => {
  return request.get<any, reqCategoryListType>(
    `/admin/product/getCategory2/${category1Id}`
  );
};

/**@requestCategoryList3  请求三级列表 */
export const requestCategoryList3 = (category2Id: number) => {
  return request.get<any, reqCategoryListType>(
    `/admin/product/getCategory3/${category2Id}`
  );
};

//以下attr的类型定义
/**@attrValueListItemType 某个属性内属性值列表的类型*/
export interface attrValueListItemType {
  id?: number;
  valueName: string;
  attrId: number | undefined;
  isEdit?: boolean;
}
/**@attrValueListType 某个属性列表的类型*/
export type attrValueListType = attrValueListItemType[];

/**@attrListItemType 属性列表每一项的类型 */
export interface attrListItemType {
  id?: number;
  attrName: string;
  categoryId: number;
  categoryLevel: number;
  attrValueList: attrValueListType;
  attrIdValueId?:string

}

/**@attrListType 属性列表的类型 */
export type attrListType = attrListItemType[];

/**@reqAttrListParams 获取属性列表的参数类型*/
export interface reqAttrListParams {
  category1Id: number;
  category2Id: number;
  category3Id: number;
}

/**@requestAttrList 获取属性列表的请求 */
export const requestAttrList = ({
  category1Id,
  category2Id,
  category3Id,
}: reqAttrListParams) => {
  return request.get<any, attrListType>(
    `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
  );
};

/**@requestAddOrUpdateAttr 添加或更新属性的请求*/
export const requestAddOrUpdateAttr = (newAttr: attrListItemType) => {
  return request.post<any, null>(`/admin/product/saveAttrInfo`, newAttr);
};

/**@requestDeleteAttr 删除属性的请求*/
export const requestDeleteAttr = (attrId: number) => {
  return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`);
};
